package com.mjh.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mjh.bean.Tran;
import com.mjh.mapper.TranMapper;
import com.mjh.model.BaseQuery;
import com.mjh.service.TranService;
import com.mjh.utils.AuthUtil;
import com.mjh.vo.CustomerVo;

import com.mjh.vo.TranVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class TranServiceImpl implements TranService {
    @Autowired
    private TranMapper tranMapper;

    @Override
    public PageInfo<CustomerVo> queryTranListByPage(Integer current, Integer size) {
        PageHelper.startPage(current, size);
        List<CustomerVo> list = tranMapper.selectList(new BaseQuery());
        return new PageInfo<>(list);
    }

    @Override
    public Boolean saveTran(Tran tran) {
        tran.setCreateBy(AuthUtil.getLoginUserId());
        tran.setCreateTime(new Date());
        return tranMapper.insert(tran)>0;
    }

    @Override
    public Boolean removeTranById(Integer id) {
        return tranMapper.deleteByPrimaryKey(Long.valueOf(id))>0;
    }

    @Override
    public Tran queryTranInfoById(Integer id) {
        return tranMapper.selectByPrimaryKey(Long.valueOf(id));
    }

    @Override
    public Boolean modifyTran(Tran tran) {
        tran.setEditBy(AuthUtil.getLoginUserId());
        tran.setEditTime(new Date());
        return tranMapper.updateByPrimaryKeySelective(tran)>0;
    }

}
